#include <iostream>
#include <cstring>
#include <algorithm>

//链接：https://www.acwing.com/problem/content/3270/
//简单的模拟即可
using namespace std;

int main(){
    int r,y,g;
    cin >> r >> y >> g;
    int n;
    cin >> n;
    int res = 0;
    for (int i = 0; i < n; i++){
        int k,t;
        cin >> k >> t;
        if (k == 1)res += t;
        else if (k == 2)res += (t + r);
        else if (k == 0)res += t;
    }
    cout << res;
    return 0;
}